package com.emath.shared;

import java.io.*;
import java.lang.Thread.UncaughtExceptionHandler;
import com.emath.objects.Game;
import com.emath.objects.Player;
import com.emath.objects.Username;

import android.app.Activity;
import android.app.AlarmManager;
import android.content.*;
import android.os.Process;

public class ExceptionHandler implements UncaughtExceptionHandler {

	Context context;
	Activity activity;
    private UncaughtExceptionHandler defaultUEH;

    /* 
     * if any of the parameters is null, the respective functionality 
     * will not be used 
     */
    public ExceptionHandler(Context thecontext,Activity theactivity) {
       context=thecontext;
       activity=theactivity;
       this.defaultUEH = Thread.getDefaultUncaughtExceptionHandler();

    }

    public void uncaughtException(Thread t, Throwable e) {
    	RestClient Connect=new RestClient();
		
		String logout = "http://emath-project.appspot.com/emath/emathservicehttp?function=logout&userID="
				+ Username.getUser();
		Connect.connect(logout);
		Connect.clear();
		
		String setpower = "http://emath-project.appspot.com/emath/emathservicehttp?function=setgame&gameID="
												+ Game.getGameID() + "&"+Player.getPlayer()+"power=1000";
		Connect.connect(setpower);
		Connect.clear();
		
		System.exit(0);
		//Process.killProcess(Process.myPid());
       // System.exit(0);
        
    //    defaultUEH.uncaughtException(t, e);
    }

   

    
}